final File srcRoot = new File("../../OSM-2/src")
assert srcRoot.isDirectory()
Collection<File> srcFiles = new ArrayList<File>()

void findSrcFiles(File dir, Collection<File> srcFiles) {
    assert dir.isDirectory()
    for (File f: dir.listFiles()) {
        if (f.name ==~ /.*\.svn/) continue
        if (f.isDirectory()) {
            findSrcFiles(f, srcFiles)
        } else {
            if (f.name ==~ /.*\.java$/) {
                srcFiles << f
            }
        }
    }
}

String capitalize(String s){
    return s.substring(0,1).toUpperCase() + s.substring(1,s.size())
}
findSrcFiles(srcRoot, srcFiles)

println "found total of ${srcFiles.size()} .java files:"
srcFiles.each { println it.getAbsolutePath() }

for (File f: srcFiles) {
    Collection<String> lines = f.getText().split('\n')
    boolean startedJDoc = false
    boolean issueFound = false
    for (int i = 0; i < lines.size(); i++) {
        String line = lines[i]
        if (line ==~ /\s*\/\*\*\s*/) {
            startedJDoc = true
            continue
        }

        if (startedJDoc) {
            startedJDoc = false
           // println line
            if (line ==~ /\s*\*\s*[a-z]\p{Alpha}*.*/) {
                issueFound = true
                println "changing: ${line}"
                String lowerCasedWord = (line =~ /^[^\p{Alpha}]+(\p{Alpha}*)[^\p{Alpha}].*/)[0][1]
                String fixedWord = capitalize(lowerCasedWord)
                String newLine = line.replaceFirst(lowerCasedWord,fixedWord)
                println "to: ${newLine}"
                lines[i] = newLine
            }
        }
        startedJDoc = false
    }

    if (issueFound) {
        String fixedFileText = lines.inject('') {x, y -> "${x}${y}\n"}
        f.setText(fixedFileText)
        println "*** FIXED FILE: ${f.getAbsolutePath()}***"
        println fixedFileText
        issueFound = false
    }


}